package com.campus.common.role.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campus.common.result.Result;
import com.campus.common.role.job.entity.Role;
import com.campus.common.role.mapper.RoleMapper;
import com.campus.common.role.service.IRoleService;
import org.springframework.stereotype.Service;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
    @Override
    public Result addRole(String name) {
        Role role=new Role();
        role.setRoleName(name);
        int i=baseMapper.insert(role);
        if(i>0){
            return Result.success();
        }
        return Result.fail("添加失败");
    }

    @Override
    public Result deleteRoleId(Integer roleId) {
        int i=baseMapper.deleteById(roleId);
        if(i>0){
            return Result.success();
        }
        return Result.fail("删除失败");    }

    @Override
    public Result getRoles(String name) {
        LambdaQueryWrapper<Role> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.like(Role::getRoleName,name);
        return Result.success(baseMapper.selectList(queryWrapper));
    }
}
